" Test Area

"=============================================================================
" Key
"=============================================================================
" <F2> : NERDTree
" <F3> : Rgrep
" <F4> : Align
" <F5> : Align
" <F6> : TlistToggle
" <F7> : svn blame
" <F9> : !xclip -f -sel clip<CR>
" <F10>: mz:-1r !xclip -o -sel clip<CR>`z
"
" ff fl fb fm: FuzzyFinder
" fi: CommandT
"
" cm ,cc
"
" gf
"
" 2,5s/\/\///g
" <C-a> ggvG$
" 
" :sp :vsp  
"
" ct  
" <C-]> c-t
"
" ,l ,lp 
" ,lk ,ll ,lw
"
"
" :%!xxd  :%!xxd -r
" hl wb ^$ jk HML <C-D><C-U> <C-F><C-B> ggG 
" x d2w d$ 3dd d} dgg
" cm ,cc
"
" yss<q> yss" ysw" ysw<b>  
" dst ds{ ds'
" cst{ cst" cs{<b> cs"'
"
"qa q @a @@ 10@a 
"
" TOhtml
"
"=============================================================================
" 0. Vundle 
"=============================================================================
  set rtp+=~/.vim/bundle/vundle/
  call vundle#rc()

  " let Vundle manage Vundle
  Bundle 'gmarik/vundle'

  " vim-scripts repos
  Bundle 'L9'
  Bundle 'FuzzyFinder'
  Bundle 'grep.vim'
  Bundle 'The-NERD-Commenter'
  Bundle 'The-NERD-tree'
  Bundle 'rails.vim'
  Bundle 'SuperTab'
  Bundle 'taglist.vim'

"=============================================================================
" 1. General settings
"=============================================================================
"1.1 Custom Settings {

  let mapleader=","

  nmap Q :q!<CR>
  nmap W :w<CR>
  nmap <C-s> :w<CR>
  nmap <C-a> ggvG$
  imap <C-a> <ESC>:w<CR>

  " <C-v> -> select ->  I -> edit -> <ESC><ESC>

  " J
  " A
  "nmap <CR> i<CR><Esc>
  " v%=  vwy

  " u <C-r> . ,vd
  " :set diff

  " :w!!
  cmap w!! %!sudo tee > /dev/null %

  "ci"    da[    vi'   ya( 

  vmap <F9> :!xclip -f -sel clip<CR>
  map <F10> mz:-1r !xclip -o -sel clip<CR>`z
"}

"1.2 indent & backspace {

  filetype plugin indent on
  set completeopt=longest,menu

  set autoindent                    "auto indent
  set backspace=indent,eol,start    "when indent/eol/start, we can backspace 
  set expandtab 					          " use space instead of tab
  set tabstop=2                     "tab 2 space
  set shiftwidth =2                 "indent 2 space
"}

"1.3 line number {
  set nu                  "line number
  set numberwidth=1 		" line number width
"}

"1.4 wrap {
  set linebreak                "do not wrap in a word
  set whichwrap=b,s,<,>,[,]  "when we can wrap
  set fo+=mB              "support wrap for Asian char
  set linebreak
"}

"1.5 list {
  set nolist                "show char space and tab
  set listchars=tab:>-,trail:-  "show what char when space and tab 
"}

"1.6 other {
  "set mouse=a             "use mouse
  set mouse=n             "don't use mouse
  set nocompatible  " no vi
  set clipboard+=unnamed " put y&p content into clipboard
  "set autochdir " set the current file dir as current working dir
  set incsearch           " do incremental searching
"}

"1.7 cursor {
  "set cursorcolumn " vertical line
  set cursorline " horizontal line
  set showmatch           "show match char
  set matchtime=5         "show match char time
  set ruler               " show the cursor position all the time
"}

"1.8 color {
  syntax enable
  syntax on
  set t_Co=256
  set hlsearch            "high light search result
  set background=dark     "background color 
  colorscheme ron         "color scheme 

  highlight Pmenu guifg=Darkblue guibg=Gray  " auto completion popup menu color
  "highlight StatusLine guifg=SlateBlue guibg=Yellow
  highlight StatusLineNC guifg=Gray guibg=White " status line color
  highlight StatusLine guifg=Gray guibg=SlateBlue

  highlight lineNr guifg=Gray guibg=Black " line number color

  "highlight CursorLine cterm=none ctermbg=2 ctermfg=0 " cursor color
  "highlight Cursorcolumn guibg=lightblue ctermbg=lightgray " cursor color
"}

"1.9 command & status {
  set cmdheight=1         "command line height
  set showcmd             " display incomplete commands
  set history=50          " keep 50 lines of command line history
  set laststatus=2

  " 设置在状态行显示的信息如下:
  " " %F 当前文件名
  " " %m 当前文件修改状态
  " " %r 当前文件是否只读
  " " %Y 当前文件类型
  " " %{&fileformat}  当前文件编码
  " " %b 当前光标处字符的 ASCII 码值
  " " %B 当前光标处字符的十六进制值
  " " %l 当前光标行号
  " " %c 当前光标列号
  " " %V 当前光标虚拟列号 (根据字符所占字节数计算)
  " " %p 当前行占总行数的百分比
  " " %% 百分号
  " " %L 当前文件总行数
  set statusline=FILE_NAME=%F%m%r%h%w,\ FILE_TYPE=%Y,\ FILE_CODE=%{&ff},\ ASCII=\%03.3b\,\ HEX=\%02.2B\,\ %l,%v(%L)\ %p%%
"}

"1.10 backup {
  set nobackup           "no backup file
  "set backupext=.bak     "backup file sufix name
  "set backupdir=$VIM/backup
  "set directory=$VIM/temp
  set nowritebackup      "no write backup
"}

"1.11 file encoding {
  set encoding=utf-8
  let &termencoding=&encoding
  set fileencodings=utf-8,gbk,ucs-bom,cp936
"}

"1.12 file type {
  filetype on
  filetype plugin on 
"}

"1.13 ttf {
  " set guifont=微软雅黑\ Monaco:h11:cANSI 

  " English characters.
  set guifont=Monaco\ 12
  " For double-width characters.
  set gfw=微软雅黑\ 12
"}


"1.14 Fold lines {
  " zc zx
  set foldenable
  " set foldmethod=marker
  set foldmethod=syntax
  set foldlevel=100
  set foldopen-=search
  set foldopen-=undo
  "nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR> 
"}

"1.15 quickfix {
  " :cl :cw :cn :cp
  " press v in quickfix window to preview
  au FileType qf :nnoremap <buffer> v <Enter>zz:wincmd p<Enter>
"}

"1.17 color scheme explorer {
  " plugin
  ":ColorSchemeExplorer
"}

"1.16 svn {
  function SvnBlame(linesOfContext)
     let pos = line(".")
     let text = system("svn blame " . expand("%:p"))
     let tempName = tempname()

     exec "redir! > " . tempName
     silent echon text
     redir END 
     execute "botr " . (a:linesOfContext * 2 + 1) . "split " . tempName
     exec pos 
     norm zz
     redraw!
  endfunction
  noremap <F7> :call SvnBlame(6)<CR>
"}

"=============================================================================
" 2 Move
"=============================================================================
"2.1 Cursor movement {
  nnoremap <Down> gj
  nnoremap <Up> gk
  vnoremap <Down> gj
  vnoremap <Up> gk
  inoremap <Down> <C-o>gj
  inoremap <Up> <C-o>gk

  nnoremap <End> g$
  nnoremap <Home> g0
  vnoremap <End> g$
  vnoremap <Home> g0
  inoremap <End> <C-o>g$
  inoremap <Home> <C-o>g0
"}

"2.2 Move lines {
  nmap <C-Down> :<C-u>move .+1<CR>
  nmap <C-Up> :<C-u>move .-2<CR>
  imap <C-Down> <C-o>:<C-u>move .+1<CR>
  imap <C-Up> <C-o>:<C-u>move .-2<CR>
  vmap <C-Down> :move '>+1<CR>gv
  vmap <C-Up> :move '<-2<CR>gv
"}

"=============================================================================
" 3 Edit
"=============================================================================
"3.1 Toggle spell check  ---  For VIM7 only {
  nmap <C-F11> :set spell!<CR>
  imap <C-F11> <C-o>:set spell!<CR>
"}

"3.2 surround {
  " plugin/surround.vim
  " yss" ysw"   ysW"  yss<q>
  " ds{ dst ds'
  " cst{  cst" cs"'
"}

"3.3 align {
  " plugin/AlignPlugin.vim
  " plugin/AlignMapsPlugin.vim

  "Go to beginning of block, type ma OR V (visual line mode)
  "Go to end of block, type \t=
 
  ":15,16Align=>
  autocmd BufReadPost *.rb silent! AlignCtrl p1P1 
  vmap <F4> :Align=><CR>
  vmap <F5> :Align=<CR>
"}

"=============================================================================
" 4 image 
"=============================================================================

"=============================================================================
" 5 search
"=============================================================================
"5.1 Genutiles{
  " plugin/genutiles.vim
"}

"5.2 Grep {
  " plugin/grep.vim
  " :Grep :Rgrep
  let Grep_Shell_Quote_Char = '"'
  let Grep_Skip_Dirs = '.svn'
  nnoremap <silent> <F3> :Rgrep -i --exclude=*.svn-base --exclude=*tags --exclude=*.log --exclude=*.swp --exclude=*.tmp<CR>
"}

"5.3 matchit {
  " plugin/matchit.vim
  " % [[ ]] [] ][
"}

"5.4 CommandT {
  nnoremap fi :CommandT <CR>
  let g:CommandTMatchWindowAtTop=1
  let g:CommandTMaxHeight=10
"}

"5.5 FuzzyFinder {
" Need L9 plugin
  " plugin/fuf.vim
  " plugin/l9.vim
  let g:fuf_modesDisable = ['mrucmd']
  let g:fuf_ignoreCase = 1
  let g:fuf_abbrevMap  = {
			 \"^co:" : [
			 \       "app/controllers/**/",
			 \],
			 \"^mo:" : [
			 \       "app/models/**/",
			 \],
			 \"^hp:" : [
			 \       "app/helpers/**/",
			 \],
			 \"^vi:" : [
			 \       "app/views/**/",
			 \],
			 \"^js:" : [
			 \       "public/javascripts/**/",
			 \],
			 \"^ss:" : [
			 \       "public/stylesheets/**/",
			 \],
			 \"^li:" : [
			 \       "lib/**/",
			 \],
			 \}

  nmap ff :FufFile<cr>
  nmap fc :FufFile co:<cr>
  nmap fm :FufFile mo:<cr>
  nmap fh :FufFile hp:<cr>
  nmap fv :FufFile vi:<cr>
  nmap fj :FufFile js:<cr>
  nmap fs :FufFile ss:<cr>
  nmap fl :FufFile li:<cr>

  nmap fb :FufBuffer<cr>
  nmap fn :FufLine <CR>
  nmap fr :FufMruFile <CR>
"}

"============================================================================
" 6 Auto completion
"============================================================================
"1. Whole lines															      |i_CTRL-X_CTRL-L|
"2. keywords in the current file									|i_CTRL-X_CTRL-N|
"3. keywords in 'dictionary'											|i_CTRL-X_CTRL-K|
"4. keywords in 'thesaurus', thesaurus-style			|i_CTRL-X_CTRL-T|
"5. keywords in the current and included files		|i_CTRL-X_CTRL-I|
"6. tags																					|i_CTRL-X_CTRL-]|
"7. file names																		|i_CTRL-X_CTRL-F|
"8. definitions or macros													|i_CTRL-X_CTRL-D|
"9. Vim command-line															|i_CTRL-X_CTRL-V|
"10. User defined completion											|i_CTRL-X_CTRL-U|
"11. omni completion															|i_CTRL-X_CTRL-O|
"12. Spelling suggestions													|i_CTRL-X_s|
"13. keywords in 'complete'												|i_CTRL-N|

"6.1 super tab {
  " plugin/supertab.vim
  let g:SuperTabRetainCompletionType=2
  let SuperTabMappingForward="<Tab>" 
  let SuperTabMappingBackward="<S-Tab>"
  "let g:SuperTabDefaultCompletionType="<C-X><C-P>"
  let g:SuperTabDefaultCompletionType="<C-X><C-U>"
"}

"6.2 SearchComplete {
  " plugin/SearchComplete.vim
  "用/或者?搜索时按tab补全要搜索的单词。
"}


"6.3 NeoComplCache {
  " <C-X><C-U>
  let g:NeoComplCache_EnableAtStartup = 1
  let g:NeoComplCache_DisableAutoComplete = 1
  let g:NeoComplCache_EnableCamelCaseCompletion = 1
  let g:NeoComplCache_SmartCase = 1
  let g:NeoComplCache_TagsAutoUpdate = 1
  let g:NeoComplCache_EnableInfo = 1
  let g:NeoComplCache_MinSyntaxLength = 3
  let g:NeoComplCache_EnableSkipCompletion = 1
  let g:NeoComplCache_SkipInputTime = '0.5'
  let g:NeoComplCache_SnippetsDir = $HOME.'/.vim/snippets'
"}

"=============================================================================
" 7 Tags
"=============================================================================
"7.1 Tlist {
  " plugin/taglist.vim
  " Need ctags
  " <C-]> c-t
  nmap <F6> :TlistToggle<CR>
  let Tlist_Show_One_File=1
  let Tlist_Exit_OnlyWindow=1
  let Tlist_Use_Right_Window=1
  let Tlist_File_Fold_Auto_Close=1
  let Tlist_WinHeight=700 
  let Tlist_WinWidth=20
"}

"7.2 CTags {
  " :cd ../../ or use nerd_tree to open a file in root dir
  nmap ct :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q<cr>
  "当前目录下有一个名为tags的目录，而ctags -R 是要产生一个tags文件，会冲突.
  set tags+=tags;
  set tags+=/var/freewheel-work/rpmui_trunk/rpm_ui_tags
  set tags+=/var/freewheel-work/rpmui_trunk/ree_tags
"}

"=============================================================================
" 8 Comments
"=============================================================================
"8.1 NERD_commenter {
  " plugin/NERD_commenter.vim 
  " ,cc ,c<space>
  let NERD_c_alt_style = 1    " 将C语言的注释符号改为//, 默认是/**/
  map cm ,c<space>gv
  vmap cm ,c<space>
"}


"=============================================================================
" 9 windows & tab 
"=============================================================================
"9.1 General Command {
  " <c-w><c-w> " switch windows
  " :sp :vsp
  nmap <silent> mm <C-W>w:set cursorline<CR>:200sl m<CR>:set nocursorline<CR>
  nmap <silent> <S-m> <C-W>p:set cursorline<CR>:200sl m<CR>:set nocursorline<CR>
  nmap <C-N> :tabnext<CR>
  nmap <C-P> :tabprev<CR>
"}

"9.2 NERDTree {
  " plugin/NERD_tree.vim 
  " plugin/fs_menu.vim 
  " plugin/exec_menuitem.vim
  " m
  " go gi gs 
  " x X O 
  " p P  c-j  c-k
  " I F B A
  " q ?  
  nnoremap <silent> <F2> :NERDTreeToggle<CR>
  let NERDChristmasTree=1
  let NERDTreeAutoCenter=1
  let NERDTreeShowFiles=1
  "let NERDTreeShowHidden=1
  let NERDTreeShowLineNumbers=1
  let NERDTreeWinPos='left'
  let NERDTreeWinSize=21
"}


"=============================================================================
" 10 Java 
"=============================================================================
" after/syntax/java.vim

"=============================================================================
" 11 C/CPP 
"=============================================================================
" after/syntax/cpp.vim
" after/syntax/c.vim

"11.1 A {
  " plugin/a.vim
  " :A :AS :AV
"}

"=============================================================================
" 12 ruby 
"=============================================================================
"12.1 Ruby Snippets {
  autocmd BufNewFile,BufRead *.rb,*.rhtml,*.haml,*.erb source ~/.vim/scripts/rubysnippets.vim
  " atr atw atc
  " def each
"}

"12.2 rails {
  " plugin/rails.vim
  " autoload/rails.vim
  " :Rmodel :Rview :Rcontroller :Rtree :R :Rmetal :Rmigration :Rlocale
"}

"12.3 haml {
  " syntax/haml.vim
"}

"12.4 vim-ruby, vim-rails {
  " vim-ruby gem install vim-ruby –remote && vim-ruby-install.rb
  " syntax/ruby.vim
  " syntax/eruby.vim
  " autoload/rubycomplete.vim
"}


"=============================================================================
" 13 Javascript 
"=============================================================================
"13.1 Javascript {
  " plugin/javascript.vim
"}

"13.2 Jquery syntax {
  au BufRead,BufNewFile *.js set syntax=jquery
"}

"=============================================================================
" 14 HTML 
"=============================================================================
"14.1 closetag {
  autocmd Filetype html,xml,xsl source ~/.vim/scripts/closetag.vim 
  " <C>-<SHIFT>-_
"}
